﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>代码文件筛选</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
   
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="筛选路径" style="padding:3px;" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
               <div style="margin: 3px 0px 3px 3px">
                    <div style="float:left">
                        <div class="divLabel" style="margin-bottom: 5px; ">
                            顶层路径：</div>
                        <input id="txtTopPath" class="easyui-textbox" name="TopPath" type="text"
                            data-options="" style="width: 600px; height: 22px" />
                    </div>
                    <div style="float:left;margin-left:10px;padding-top:22px">
                        <input id="ckFilter" type="checkbox" title="只筛选本级路径,不找子路径" /><span>只筛选此路径</span> 
                    </div>
                    <div style="float:left;margin-left:10px">
                        <div class="divLabel" style="margin-bottom: 5px; ">
                            起始日期：</div>
                        <input id="txtStart" type="text" class="easyui-datebox" style="height:22px">
                    </div>
                    <div style="float:left;margin-left:10px">
                        <div class="divLabel" style="margin-bottom: 5px; ">
                            格式：</div>
                        <input id="txtFormat" class="easyui-textbox" name="Format" type="text"
                            data-options="value:'vb;cs;aspx;html;htm;js;css;ashx'" style="width: 400px; height: 22px" />
                    </div>
                   <div style="clear:both" ></div> 
                     <div style="">                        

                        <div class="divLabel" style="margin-bottom: 5px; ">
                            子路径(多个用;分割)：</div>
                        <input id="txtSonPath" class="easyui-textbox" name="SonPath" type="text"
                            data-options="multiline:true" style="width: 600px; height: 300px" />
                    </div>
                </div>
        </div> 

    </div> 
    <div class="panelSection">    
        <div class="easyui-panel " title="结果路径" style="padding:3px;" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <div style="">
                <div class="divLabel" style="margin-bottom: 5px; ">
                    结果路径：</div>
                <input id="txtTargetPath" class="easyui-textbox" name="TargetPath" type="text"
                    data-options="" style="width: 600px; height: 22px" />
            </div>
        </div>
    </div>
    <div class="panelSection">    
        <div class="easyui-panel " title="操作区域" style="padding:3px;" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
             <button  id="btnExport" class="easyui-linkbutton" data-options="" title="注意会先清除结果路径" style="margin-left:0px">
                        筛选文件</button> 
             <button  id="btnExportAndDown" class="easyui-linkbutton" data-options="" title="注意会先清除结果路径" style="margin-left:20px">
                        筛选文件并下载</button> 
        </div>
    </div>

    <div id="dlg" class="easyui-dialog" title="筛选出的文件" data-options="closed:true" style="width: 100%; height: 500px; padding: 10px">
       <a href="#" id="dlg-downFile" style="display:none" >下载筛选的文件</a>
       <ul id="dl" class="easyui-datalist" title=""  style="width:100%;height:100%"></ul>
       
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    var page = {
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/HomeHandler.ashx",
        //初始化
        init: function () {
            //初始值
            $("#txtTopPath").textbox('setValue','C:\\Program Files (x86)\\Camstar\\InSite Web Application');
            $("#txtSonPath").textbox('setValue','\\uMESBusinessRule;'+'\r'+
            '\\uMESDatabaseAccess\\DatabaseAccess.DBUtility;'+'\r'+
            '\\uMESExternalInterface\\ExternalInterface;' + '\r' +
            '\\uMESExternalControl;' + '\r' +
            '\\InSiteWebApplication\\forms\\Custom;'+'\r'+
            '\\InSiteWebApplication\\forms\\ApsPages;'+'\r'+
            '\\InSiteWebApplication\\Ashx;'+'\r'+
            '\\InSiteWebApplication\\Scripts;'+'\r'+
            '\\InSiteWebApplication\\App_Code;'+'\r'+
            '\\InSiteWebApplication\\Home;');
            $("#txtTargetPath").textbox('setValue','C:\\Program Files (x86)\\Camstar\\InSite Web Application\\InSiteWebApplication\\Temp2\\代码导出');

            $('#btnExport').on("click", function () {
                page.filterCodeFiles();
            });

            $('#btnExportAndDown').on("click", function () {
                page.filterCodeFilesAndDown();
            });

            //初始化datalist
            $("#dl").datalist({
                lines:true,valueField:'value',textField:'text',groupField: 'group',
                groupFormatter:function(value,rows){
                    return value+"--"+rows.length+"项";
                }
            });
        }
        , filterCodeFiles: function () {
            var param = {
                action:"filterCodeFiles",
                topPath: $("#txtTopPath").textbox('getValue'),
                sonPath:$("#txtSonPath").textbox('getValue'),
                startDate:$("#txtStart").datebox('getValue'),
                targetPath:$("#txtTargetPath").textbox('getValue'),
                fileFormat:$("#txtFormat").textbox('getValue'),
                firstDir:$("#ckFilter").prop("checked")
            };

            if(isNullOrWhiteSpaceStr(param.topPath)||isNullOrWhiteSpaceStr(param.sonPath)||isNullOrWhiteSpaceStr(param.startDate)||isNullOrWhiteSpaceStr(param.targetPath)||isNullOrWhiteSpaceStr(param.fileFormat)){
                displayMessage("请输入必填项",false);
                return;
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //console.log(data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        //给分页对象赋值
                        //console.log(result.ReturnData);
                        $("#dlg").dialog('open');
                        if(result.ReturnData.length>0){                            
                            var dlData=[];
                            result.ReturnData.forEach(function(item,index){
                                //console.log(item.substr(0,item.lastIndexOf("\\")));
                                dlData.push({value:index,text:item,group:item.substr(0,item.lastIndexOf("\\"))});
                            });
                            $("#dl").datalist('loadData',dlData);
                        }                        
                        displayMessage("已筛选到结果路径中，共："+result.ReturnData.length+"个文件", true);
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    alert(XMLHttpRequest.responseText);
                }
            });
        }
        , filterCodeFilesAndDown: function () {
            var param = {
                action:"filterCodeFilesAndDown",
                topPath: $("#txtTopPath").textbox('getValue'),
                sonPath:$("#txtSonPath").textbox('getValue'),
                startDate:$("#txtStart").datebox('getValue'),
                targetPath:$("#txtTargetPath").textbox('getValue'),
                fileFormat: $("#txtFormat").textbox('getValue'),
                firstDir: $("#ckFilter").prop("checked")
            };
            if(isNullOrWhiteSpaceStr(param.topPath)||isNullOrWhiteSpaceStr(param.sonPath)||isNullOrWhiteSpaceStr(param.startDate)||isNullOrWhiteSpaceStr(param.targetPath)||isNullOrWhiteSpaceStr(param.fileFormat)){
                displayMessage("请输入必填项",false);
                return;
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //console.log(data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        //给分页对象赋值
                        //console.log(result.ReturnData);
                        $("#dlg").dialog('open');
                        if(result.ReturnData.length>0){                            
                            var dlData=[];
                            result.ReturnData.forEach(function(item,index){
                                //console.log(item.substr(0,item.lastIndexOf("\\")));
                                dlData.push({value:index,text:item,group:item.substr(0,item.lastIndexOf("\\"))});
                            });
                            $("#dl").datalist('loadData',dlData);
                        }                        
                        displayMessage("已筛选到结果路径中，共："+result.ReturnData.length+"个文件", true);
                        //下载按钮赋值
                        $("#dlg-downFile").css("display","inline-block");
                        $("#dlg-downFile").attr("href",page.rootPath+result.Message);
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    alert(XMLHttpRequest.responseText);
                }
            });
        }
    }

    $(function () { 
        page.init();
    })
</script>
